package com.pdemo.core.entity;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonView;
import com.pdemo.core.genericdao.BaseEntity;

@Entity
@Table(name="SYSTEM_ADMIN")
public class SystemAdmin extends BaseEntity{
	private static final long serialVersionUID = -8619375710073761304L;
	
	@Column(name="NAME", length= 25)
	@JsonView(Views.Client.class)
	private String name;
	
	@Column(name="EMAIL", length=30)
	@JsonView(Views.Client.class)
	private String email;
	
	@Column(name="MOBILE", length=13)
	@JsonView(Views.Admin.class)
	private String mobile;
	
	@Column(name="PASSWORD", length=128)
	@JsonView(Views.Admin.class)
	private String password;
	
	@Column(name="ENABLED")
	private Boolean enabled = Boolean.TRUE;
	
	@Column(name="LOCKED")
	private Boolean locked = Boolean.FALSE;
	
	@Column(name="FAILED_LOGIN")
	private Integer failedLogin;
	
	@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
    @JoinTable(name = "SYSTEM_ADMIN_ROLE", joinColumns = { @JoinColumn(name ="ADMIN_ID" )}, inverseJoinColumns = { @JoinColumn(name = "ROLE_ID") })
	@OrderBy("ID")
	@JsonView(Views.Admin.class)
	private Set<SystemRole> roles;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public Boolean isLocked() {
		return locked;
	}

	public void setLocked(boolean locked) {
		this.locked = locked;
	}

	public Integer getFailedLogin() {
		return failedLogin;
	}

	public void setFailedLogin(Integer failedLogin) {
		this.failedLogin = failedLogin;
	}

	public Set<SystemRole> getRoles() {
		return roles;
	}

	public void setRoles(Set<SystemRole> roles) {
		this.roles = roles;
	}
}
